﻿/*-----------------------------------------------------------------
 * <copyright file="StaffEntrySpeedQuery.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang Jun</author>
 * <summary> 
 *      全员别 日别 数据查询
 *      作成日： 07/12/2010
 *              04/26/2011 增加 线路名，案件名 查询条件。
 *              07/06/2011 修改 账票种类查询方式。v2.15
 *                         修改 文字种类查询方式。v2.15
 *                         修改 JobClass种类查询方式。v2.15
 *
 * </summary>
 *-----------------------------------------------------------------
 **/
namespace Orid.Management.Statistics.OperatorUnitMangement.Command.STAFF
{
    using System;
    using System.Collections.ObjectModel;
    using System.Windows;
    using System.Windows.Media;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.FunctionList;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.SearchCtrl;
    using Orid.Management.Statistics.OperatorUnitMangement.WCFLog4Ref;
    using Orid.Management.Statistics.OperatorUnitMangement.WCFServers.StaffQueryRef;
    using childWindow = Orid.Management.Statistics.OperatorUnitMangement.Common.Window;
    using Wcf = Orid.Management.Statistics.OperatorUnitMangement.Common.Service;
    using System.Text;

    /// <summary>
    /// 全员别 日别 数据查询
    /// </summary>
    public class StaffEntrySpeedQuery : ICommand
    {
        /// <summary>
        /// 全员别 日别 查询服务定义 wcfStaffEntrySpeedQueryClient
        /// </summary>
        private WCFStaffCorrelationClient wcfStaffEntrySpeedQueryClient;
       
        /// <summary>
        /// 查询控件对象 StaffSelContainer
        /// </summary>
        private StaffSelContainer container;

        /// <summary>
        /// 错误提示对话框 errorMessbox
        /// </summary>
        private childWindow.MessageBox errorMessbox;
      
        /// <summary>
        /// 日志服务定义 wcfLogClient
        /// </summary>
        private WCFLog4Client wcfLogClient;

        /// <summary>
        /// 构造函数 StaffDurEntrySpeedQuery
        /// </summary>
        /// <param name="container">查询控件 container</param>
        public StaffEntrySpeedQuery(Common.SearchCtrl.StaffSelContainer container)
        {
            this.container = container;

            this.InitField();
        }

        /// <summary>
        /// 查询完成事件 ExecOver
        /// </summary>
        public event EventHandler<SelectStaffEntrySpeedQueryInforCompletedEventArgs> ExecOver;
       
        /// <summary>
        /// 查询开始事件 ExecBegin
        /// </summary>
        public event EventHandler<EventArgs> ExecBegin;


        /// <summary>
        /// 查询完成事件 OnExecover
        /// </summary>
        /// <param name="sender">Sender of Object</param>
        /// <param name="e">e type of SelectOPWorkEfficiencyCompletedEventArgs</param>
        protected void OnExecover(object sender, SelectStaffEntrySpeedQueryInforCompletedEventArgs e)
        {
            if (this.ExecOver != null)
            {
                this.ExecOver(this, e);
            }
        }

        /// <summary>
        /// 查询开始事件 OnExecBegin
        /// </summary>
        /// <param name="sender">Sender of Object</param>
        /// <param name="e">e type of EventArgs</param>
        protected void OnExecBegin(object sender, EventArgs e)
        {
            if (this.ExecBegin != null)
            {
                this.ExecBegin(this, e);
            }
        }

        /// <summary>
        /// 初始化变量 InitField
        /// </summary>  
        private void InitField()
        {
            this.wcfStaffEntrySpeedQueryClient = Wcf.Service.StaffEntrySpeedQuery;

            this.errorMessbox = new childWindow.MessageBox();

            this.wcfLogClient = Wcf.Service.Log4;

            // 全员别 日别 查询(委托)
            this.wcfStaffEntrySpeedQueryClient.SelectStaffEntrySpeedQueryInforCompleted += new EventHandler<SelectStaffEntrySpeedQueryInforCompletedEventArgs>(this.OnExecover);
        }


        #region ICommand 成员
        /// <summary>
        /// 全员别日别 Exec
        /// </summary>
        public void Exec()
        {
            // 传送到服务端的参数列表
            ObservableCollection<WCFServers.StaffQueryRef.WhereParameters> clientWhereList = new ObservableCollection<WCFServers.StaffQueryRef.WhereParameters>();

            // this.tbOPID.Text dpDateFrom dpDateTo内容必选的判断
            // 日期不能相同
            // 开始日期不能小于结束日期
            int error = FunctionClass.IsSelectDo(
                                        this.container.dpDateFrom,
                                        this.container.dpDateTo,
                                        this.errorMessbox);

            if (error == 0)
            {
                this.container.btnSelectAllInfor.IsEnabled = true;
                return;
            }

            try
            {
                try
                {
                    //传送数据不加单引号
                    #region  组合条件
                    // 组合客户端的WHERE条件
                    WCFServers.StaffQueryRef.WhereParameters fitWhereData = new WCFServers.StaffQueryRef.WhereParameters();

                    // 日期的判断条件
                    // 日期返回空值用"null"
                    if (!String.IsNullOrEmpty(this.container.dpDateFrom.Text))
                    {
                        fitWhereData.WhereentryDateFrom = this.container.dpDateFrom.SelectedDate.Value.ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        fitWhereData.WhereentryDateFrom = "null";
                    }

                    if (!String.IsNullOrEmpty(this.container.dpDateTo.Text))
                    {
                        fitWhereData.WhereentryDateTo = this.container.dpDateTo.SelectedDate.Value.ToString("yyyy-MM-dd");
                    }
                    else
                    {
                        fitWhereData.WhereentryDateTo = "null";
                    }

                    //// 帐票种类
                    //fitWhereData.WhereScriptType = FunctionClass.MyIsNullOrEmpty(this.container.tbACCOUNTVOTES.Text.Trim().ToString(), null);

                    //// job种类
                    //fitWhereData.WhereJobClass = FunctionClass.MyIsNullOrEmpty(this.container.tbJOB.Text.Trim().ToString(), null);

                    //// 文字种类
                    //fitWhereData.WhereWordType = FunctionClass.MyIsNullOrEmpty(
                    //                                                this.container.tbWordType.Text.Trim().ToString(),
                    //                                                null);

                    // 帐票种类选择条件 07/05/2011 v2.15
                    if (ClientDataList.SelScriptTypeList.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in ClientDataList.SelScriptTypeList)
                        {
                            // 添加逗号
                            sb.Append(s + ",");
                        }

                        // 去除尾部多余逗号
                        fitWhereData.WhereScriptType = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                    }
                    // job种类 选择条件 07/06/2011 v2.15
                    if (ClientDataList.SelJobClassList.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in ClientDataList.SelJobClassList)
                        {
                            // 添加逗号
                            sb.Append(s + ",");
                        }

                        // 去除尾部多余逗号
                        fitWhereData.WhereJobClass = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                    }

                    // 文字种类选择条件 07/06/2011 v2.15
                    if (ClientDataList.SelWordTypeList.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in ClientDataList.SelWordTypeList)
                        {
                            // 添加逗号
                            sb.Append(s + ",");
                        }

                        // 去除尾部多余逗号
                        fitWhereData.WhereWordType = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                    }

                    // LINE选择条件 04/26/2011 v2.14
                    if (ClientDataList.SelLineList.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in ClientDataList.SelLineList)
                        {
                            // 添加逗号
                            sb.Append(s + ",");
                        }
                        // 去除尾部多余逗号
                        fitWhereData.WhereServer = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                    }


                    // 案件名选择条件 04/26/2011 v2.14
                    if (ClientDataList.SelMatterNamesList.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string s in ClientDataList.SelMatterNamesList)
                        {
                            // 添加逗号
                            sb.Append(s + ",");
                        }

                        // 去除尾部多余逗号
                        fitWhereData.WhereMatterName = sb.ToString().Remove(sb.ToString().Length - 1, 1);
                    }

                    // 将类增加到  参数列表中
                    clientWhereList.Add(fitWhereData);

                    #endregion  组合条件
                }
                catch (Exception ex)
                {
                    this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + " 全员别日别接口实现类 StaffEntrySpeedQuery 转换查询条件出错" +
                                        ex.Message.ToString());

                    Common.FunctionList.FunctionClass.ShowMessageBox(
                       this.errorMessbox,
                       1,
                       "转换查询条件出错",
                       ex.Message.ToString(),
                       Colors.Gray,
                       true,
                       Visibility.Visible,
                       Visibility.Collapsed);
                    return;
                }

                this.OnExecBegin(null, null);

                // 调用 全员别 日别 服务端方法
                this.wcfStaffEntrySpeedQueryClient.SelectStaffEntrySpeedQueryInforAsync(clientWhereList);

                clientWhereList.Clear();
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + " 全员别日别接口实现类 StaffEntrySpeedQuery  调用SelectStaffEntrySpeedQueryInforAsync服务出错" + ex.Message.ToString());

                Common.FunctionList.FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "调用SelectStaffEntrySpeedQueryInfor服务出错",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion
    }
}
